﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace NGUYENTHANHDONG.Excercise_lv2.Bai4
{
    public partial class Rectange : Form
    {
        public Rectange()
        {
            InitializeComponent();
        }

        private void Rectange_Load(object sender, EventArgs e)
        {
            cmbLuaChon.Items.Add("Chu Vi");
            cmbLuaChon.Items.Add("Diện Tích");
            cmbLuaChon.SelectedIndex = 0;

            txtKetQua.Enabled = false;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            erpLoi.Clear();

            if(string.IsNullOrEmpty(txtWidth.Text))
            {
                erpLoi.SetError(txtWidth, "khong dc de trong !!");
                txtWidth.Focus();
            }
            else if(string.IsNullOrEmpty(txtHeight.Text))
            {
                erpLoi.SetError(txtWidth, "khong dc de trong !!");
                txtHeight.Focus();
            }
            else
            {
                CONTROLLERS con = new CONTROLLERS();
                UserEntity objUser;

                if(cmbLuaChon.Text == "Chu Vi")
                {
                    objUser = new UserEntity(double.Parse(txtWidth.Text), double.Parse(txtHeight.Text), 1);
                    txtKetQua.Text = con.tinh(objUser) + " ";
                }
                else

                {
                     objUser = new UserEntity(double.Parse(txtWidth.Text), double.Parse(txtHeight.Text), 2);
                    txtKetQua.Text = con.tinh(objUser) + " ";
                }
            }
        }
    }
}
